(function ($) {
	$(function(){
	    var height=$(window).height();
    var width=$(window).width();
    $("#loading").height(height);
     $("#loading").width(width);
		loading();
			});
})(jQuery);

var loading = function(){
    
	var loaderCount = 0;
	var loaderImages = [];
	var currentCou = 0;
	
	loaderImages = $.merge(loaderImages, [
	"../../img/main/main_bg01.gif",  
	"../../img/main/main_bg02.png",  
    "../../img/main/main_cloud01.png",
    "../../img/main/main_cloud02.png",
    "../../img/main/main_cloud03.png",
    "../../img/main/main_cloud04.png",
    "../../img/main/main_cloud05.png",
    "../../img/main/main_dragon01.png",
    "../../img/main/main_dragon02.png",
    "../../img/main/main_flag01.png",
    "../../img/main/main_flag02.png",
    "../../img/main/main_ico01.png",
    "../../img/main/main_logo01.png",
    "../../img/main/main_map_bg01.png",
    "../../img/main/main_map_bg02.png",
    "../../img/main/main_map_bg03.png",
    "../../img/main/main_pic01.png",
    "../../img/main/main_Q01_on.png",
    "../../img/main/main_Q01_out.png",
    "../../img/main/main_Q02_on.png",
    "../../img/main/main_Q02_out.png",
    "../../img/main/main_ufo_hat_1.png",
    "../../img/main/main_ufo_hat_2.png",
    "../../img/main/main_ufo_hat_bg.png",
    "../../img/main/main_ufo_lotus_1.png",
    "../../img/main/main_ufo_lotus_2.png",
    "../../img/main/main_ufo_lotus_bg.png",
    "../../img/main/start_loading.gif"]);
	
    
	var loadImages = function (){
		var imgObj = new Image();		
		if(imgObj.addEventListener){
			loaderCount++;
			imgObj.addEventListener('load', function(){
				var percent = Math.floor(Number(loaderCount / loaderImages.length * 100));
				$("#percent").text(percent + "%");
				if(loaderCount === loaderImages.length-1){				    
					finishFunc();
				}else{
					loadImages();
				}
			},false);}
		 else if(imgObj.attachEvent){
			loaderCount++;
			imgObj.attachEvent('onload', function(){
			    var percent = Math.floor(Number(loaderCount / loaderImages.length * 100));
                $("#percent").text(percent + "%");
				if(Number(loaderImages.length - 1) == loaderCount){
					finishFunc();
				}else{					
					loadImages();
				}
			},false);
		}
		
		imgObj.src = loaderImages[loaderCount];
	}
	var finishFunc=function(){
	    $("#content").text("Xin Chào");
	    $("#percent").text("");
	    $("#lotus").fadeOut("slow");	   
	    $("#star").fadeIn("slow");
	   //   timeout = window.setTimeout(load(), 200000);
	     
	     
	}
	var load=function(){
	    this.document.location.href = "main.html"; 
	}

	loadImages();
	
};//loading
